package org.dairy.farms.model;

import org.dairy.farms.interceptor.hibernate.Auditable;

import javax.persistence.*;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

/**
 * Created by IntelliJ IDEA.
 * User: gduggira
 * Date: Jun 9, 2011
 * Time: 9:26:20 AM
 */
@Table(name = "EXPENSE")
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
@DiscriminatorColumn(name = "EXPENSE_FOR")
public abstract class Expense implements Auditable {

    @javax.persistence.Column(name = "ID")
    @Id
    @GeneratedValue
    private Long id;

    @ManyToOne
    @JoinColumn(name = "EXPENSE_TYPE_ID")
    private ExpenseType expenseType;

    @javax.persistence.Column(name = "AMOUNT")
    private float amount;

    @javax.persistence.Column(name = "PAYMENT_DATE")
    private Date paymentDate;

    @OneToMany(mappedBy = "expense", targetEntity = ExpenseNotes.class, fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    private Set<ExpenseNotes> expenseNotes = new HashSet<ExpenseNotes>();

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public ExpenseType getExpenseType() {
        return expenseType;
    }

    public void setExpenseType(ExpenseType expenseType) {
        this.expenseType = expenseType;
    }

    public float getAmount() {
        return amount;
    }

    public void setAmount(float amount) {
        this.amount = amount;
    }

    public Date getPaymentDate() {
        return paymentDate;
    }

    public void setPaymentDate(Date paymentDate) {
        this.paymentDate = paymentDate;
    }

    public Set<ExpenseNotes> getExpenseNotes() {
        return expenseNotes;
    }

    public void setExpenseNotes(Set<ExpenseNotes> expenseNotes) {
        this.expenseNotes = expenseNotes;
    }

    @Embedded
    private AuditInfo auditInfo = new AuditInfo();

    public AuditInfo getAuditInfo() {
        return auditInfo;
    }

    public void setAuditInfo(AuditInfo auditInfo) {
        this.auditInfo = auditInfo;
    }
}
